package userInterface.Panels.CommandArgumentPanels;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.List;
import javax.swing.*;
import javax.swing.event.*;

/**
 * {@link userInterface.panels.CommandArgumentPanels.PanelCommandArguments PanelCommandArguments} for editing
 * {@link settings.Action.Action#LOG Action.LOG} {@link settings.Command Command} arguments.
 * @author BDS
 */
public class PanelLogArguments extends PanelCommandArguments
{
	private static final long serialVersionUID = 1L;
	
	private GridBagLayout gblLogArguments;
	
	private JLabel lblMessage;
	private JTextField txtMessage;

	/**
	 * Class constructor.
	 */
	public PanelLogArguments()
	{
	    gblLogArguments = new GridBagLayout();
	    gblLogArguments.columnWidths = new int[] { 100, 0 } ;
	    gblLogArguments.columnWeights = new double[] { 0.0, 1.0 };
		setLayout(gblLogArguments);

		lblMessage = new JLabel("Message:");
        GridBagConstraints gbc_lblMessage = new GridBagConstraints();
        gbc_lblMessage.anchor = GridBagConstraints.WEST;
        gbc_lblMessage.insets = new Insets(0, 0, 5, 5);
        gbc_lblMessage.gridx = 0;
        gbc_lblMessage.gridy = 0;
        add(lblMessage, gbc_lblMessage);

		txtMessage = new JTextField();
        GridBagConstraints gbc_txtMessage = new GridBagConstraints();
        gbc_txtMessage.fill = GridBagConstraints.HORIZONTAL;
        gbc_txtMessage.insets = new Insets(0, 0, 5, 0);
        gbc_txtMessage.gridx = 1;
        gbc_txtMessage.gridy = 0;
        add(txtMessage, gbc_txtMessage);
	}
	
    /**
     * Sets the enabled state of contained controls.
     * @param enabled Determines the enabled state of contained controls.
     */
    @Override
    public void setEnabled(boolean enabled)
    {
        super.setEnabled(enabled);
        
		lblMessage.setEnabled(enabled);
		txtMessage.setEnabled(enabled);
	}
	
    /**
     * Provides the external event processing class references to the contained {@link javax.swing.JComponent JComponents}.
     * @param actionListener The {@link java.awt.event.ActionListener ActionListener} for {@link javax.swing.JComboBox JComboBoxes}.
     * @param focusAdapter The {@link java.awt.event.FocusAdapter FocusAdapter} for {@link javax.swing.JFormattedTextField JFormattedTextFields}.
     * @param keyAdapter The {@link java.awt.event.KeyAdapater KeyAdapater} for {@link javax.swing.JFormattedTextField JFormattedTextFields}.
     * @param changeListener The {@link javax.swing.event.ChangeListener ChangeListener} for {@link javax.swing.JSpinner JSpinners}.
     */
	@Override
	public void addActionListeners(ActionListener actionListener, FocusAdapter focusAdapter, KeyAdapter keyAdapter, ChangeListener changeListener)
	{ 
		txtMessage.addFocusListener(focusAdapter);
		txtMessage.addKeyListener(keyAdapter);
	}
	
    /**
     * Gets the {@link settings.Action.Action#LOG Action.LOG} {@link settings.Command} arguments currently displayed.
     * @return The {@link settings.Action.Action#LOG Action.LOG} {@link settings.Command} arguments currently displayed.
     */
	@Override
	public List<String> getArguments() 
	{ 
		List<String> arguments = new ArrayList<String>();
		
		arguments.add(txtMessage.getText());
		
		return arguments;
	}
	
    /**
     * <ul>
     *     <li>Sets the {@link settings.Action.Action#LOG Action.LOG} {@link settings.Command Command} arguments.</li>
     *     <li>Updates the UI based on the given arguments.</li>
     * </ul>
     * @param arguments The {@link settings.Action.Action#LOG Action.LOG} {@link settings.Command Command} arguments used to update the UI.
     */
	@Override
	public void setArguments(List<String> arguments) 
	{
		if (arguments != null && arguments.size() > 0 && arguments.get(0) != null)
		{
			txtMessage.setText(arguments.get(0));
		}
		else
		{
			txtMessage.setText("");
		}
	}
}
